package io.github.jdk21study.springboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.embedded.tomcat.TomcatProtocolHandlerCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.Executors;

@SpringBootApplication
@RestController
public class Application {
	@Bean
	public TomcatProtocolHandlerCustomizer<?> protocolHandler() {
		return protocolHandler ->
				protocolHandler.setExecutor(Executors.newThreadPerTaskExecutor(Thread.ofVirtual()
								.name("tomcat call ",1)
						.factory()));
	}

	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}

	@GetMapping("/hello")
	public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
		System.out.println("thread name"+Thread.currentThread().getName());
		return String.format("Hello %s!", name);
	}
	@GetMapping("/ping")
	public Message ping() {
		return new Message("pong");
	}

	public record Message(String message){}
}
